<?php
class OrgSpace_Controller extends OrgController {

    public function __construct() {
        parent::__construct();
        $this->activeMenuItem = OrgMenu::$WELCOME;
    }

    public function index() {
        $this->redirect('/org/orgSpace/welcome');
    }
    
    public function welcome() {
        // Select upcoming seminars
        $this->viewData['upcomingSeminarList'] = $this->dao->queryAll(
                'SELECT semi.*, l10n.name, l10n.description ' .
                'FROM seminar semi ' .
                'LEFT OUTER JOIN seminar_l10n l10n ON semi.id = l10n.seminar_id AND l10n.language_code = :language_code ' .
                'WHERE end_date >= :end_date ORDER BY begin_date ASC, begin_time ASC LIMIT 3',
                array(
                    'end_date' => sql::$TODAY,
                    'language_code' => $this->getL10nLanguageCode()
                ));
        foreach ($this->viewData['upcomingSeminarList'] as &$seminar) {
            $seminar['registrationCount'] = $this->dao->countValidRegistrationsBySeminarAndOrg($seminar['id'], $this->getAuthOrg('id'));
            $seminar['unconfirmedRegistrationCount'] = $this->dao->countUnconfirmedRegistrationsBySeminarAndOrg($seminar['id'], $this->getAuthOrg('id'));
            $seminar['paymentAcceptance'] = $this->dao->queryOne(
                    'SELECT * FROM payment_acceptance WHERE seminar_id = :seminar_id AND organization_id = :organization_id',
                    array('seminar_id' => $seminar['id'], 'organization_id' => $this->getAuthOrg('id')));
        }
        
        $this->renderSubview('/org/welcome');
    }
    
    public function personDisplay() {
        $personId = $this->input->get('id');
        
        if (! valid::isId($personId)) {
            $this->redirectToList('error.invalidId');
        }

        $person = $this->dao->fetchPersonById($personId);
        if (! $person) {
            $this->msg->error('error.recordNotFound');
            $this->redirect('/org/orgSpace/welcome');
        }

        $this->viewData['person'] = $person;
        $this->renderSubview('/org/orgPersonDisplay');
    }
}
